package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.Contract;
import com.zzyl.entity.NursingProject;
import com.zzyl.entity.NursingProjectPlan;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.NursingPlanProjectMapper;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.ContractVo;
import com.zzyl.vo.NursingProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class NursingProjectserviceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;


    @Override
    public PageResponse<NursingProjectVo> selectByPage(Integer pageNum, Integer pageSize, Integer status, String name) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        Page<List<NursingProject>> page = nursingProjectMapper.selectByPage(status, name);
        return PageResponse.of(page, NursingProjectVo.class);
    }

    @Override
    public void addNuringProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        //1,判断护理项目名称是否唯一
        Object obj = nursingProjectMapper.selectByName(nursingProject.getName());
        if (obj != null) {
            throw new BaseException(BasicEnum.BED_INSERT_FAIL);
        }
        //新增护理项目的详细数据
        nursingProjectMapper.insertNurseproject(nursingProject);
    }

    @Override
    public NursingProjectVo selectById(Integer id) {

        NursingProjectVo vo = nursingProjectMapper.selectById(id);

        return vo;
    }

    @Override
    public void editStatus(Integer id, Integer status) {
        nursingProjectMapper.editStatus(id,status);

    }

    @Override
    public void deleteById(Integer id) {
        nursingProjectMapper.deleteById(id);


    }

    @Override
    public List<NursingProjectVo> findAll() {
        List<NursingProjectVo> vo=  nursingProjectMapper.findAll();
        return vo;
    }

    @Override
    public void editNursingProject(NursingProjectDto nursingProjectDto) {
        log.info("前端返回的id：{}",nursingProjectDto.getId());
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.editNursingProject(nursingProject);
    }
}
